package com.bhs.sansong.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bhs.sansong.R;
import com.bhs.sansong.net.NetCallBack;
import com.bhs.sansong.utils.MyUtils;


/**
 * 红包领取
 */
public class RedPacketDialog extends Dialog implements View.OnClickListener {

    private FrameLayout mFlClose;
    private TextView mTvRedPacket;
    private ImageView mIvOpen;
    private Button mBtnTake;
    private String money;

    public RedPacketDialog(@NonNull Context context, String money) {
        super(context, R.style.MyBottomDialogStyle);
        this.money = money;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_red_packet);
        //获取当前Activity所在的窗体
        Window dialogWindow = getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = MyUtils.getScreenWidth(getContext()) * 8 / 10;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp); //将属性设置给窗体
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView() {
        mFlClose = findViewById(R.id.fl_close);
        mTvRedPacket = findViewById(R.id.tv_redPacket);
        mIvOpen = findViewById(R.id.iv_open);
        mBtnTake = findViewById(R.id.btn_take);
        mFlClose.setOnClickListener(this);
        mBtnTake.setOnClickListener(this);
        mIvOpen.setOnClickListener(this);
        mTvRedPacket.setText(String.format("%s元", money));
    }

    @Override
    public void onClick(View view) {
        dismiss();
    }
}
